#coding=utf-8
import os
import pycurl

host = "http://file-server0.appspot.com/"
#host = "http://localhost:8080/test/"
#host = "http://localhost:8080/"
def upload_file(fn, name=None):
    if not name: name = os.path.basename(fn)
    #print name
    c = pycurl.Curl()
    
    c.setopt(c.POST, 1)
    c.setopt(c.URL, host)

    c.setopt(c.HTTPPOST, [('name', name),("file", (c.FORM_FILE, fn))])

    c.setopt(c.VERBOSE, 1)
    
    c.perform()
    c.close()


if __name__ == "__main__":
    import sys
    upload_file(sys.argv[1])
